package com.upb.webserver.overview;

import com.upb.webserver.account.AccountService;
import com.upb.webserver.common.pojo.account.AccountCommon;
import com.upb.webserver.common.pojo.base.BasePageResponse;
import com.upb.webserver.common.pojo.base.BaseResponse;
import com.upb.webserver.common.pojo.overview.RspOverviewVO;
import com.upb.webserver.common.tools.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping(value = "overview")
public class OverviewController {
    @Autowired
    private OverviewService overviewService;
    @Autowired
    private AccountService accountService;

    @GetMapping
    public BaseResponse getOverview(HttpServletRequest request) {
        log.info("start exec method [getOverview].");
        //get AccountCommon
        AccountCommon accountCommon = accountService.getAccountCommon(request);
        RspOverviewVO rspOverviewVO = overviewService.getOverView(accountCommon.getPlatform(), accountCommon.getId());

        BaseResponse response = BaseResponse.initSuccess();
        response.setData(rspOverviewVO);

        log.info("success exec method [getOverview]. result:{}", JsonUtils.objToString(response));
        return response;
    }
}
